home *** CD-ROM | disk | FTP | other *** search
- Using a dictionary to count the number of occurrences of the elements in
- a sequence of strings, terminated by string ``stop''.
- \smallskip
- \#include \<LEDA/dictionary.h\>
- \smallskip
- \cleartabs
- \+main()\cr
- \+$\{$\ \ &\cr
- \+ &dictionary\<string,int\> $D$;\cr
- \smallskip
- \+ &string $s$;\cr
- \+ &dic\_item $it$;\cr
- \smallskip
- \+ &{\bf while} &(cin \>\> $s$)\cr
- \+ &\ \ &$\{$ &$it = D$.lookup($s$);\cr
- \+ & & &if ($it==nil$) $D$.insert($s,1$);\cr
- \+ & & &else $D$.change\_inf($it$,$D$.inf($it$)+1);\cr
- \+ & &\ $\}$\cr
- \smallskip
- \+ &{\bf forall\_items}($it,D$)
- cout \<\< $D$.key($it$) \<\< `` : " \<\< $D$.inf($it$) \<\< ``$\backslash$n";\cr
- \smallskip
- \+\ $\}$\cr
-
-